Page({
  data: {
    list: [],

    current: 1,
    pageSize: 10,

    refreshing: false,
  },

  async refresh() {
    this.setData({
      current: 1,
      list: [],
    })
    await this.getList(this.data.current, this.data.pageSize)
    this.setData({
      refreshing: false,
    })
  },

  onScrollToLower() {
    const { current, pageSize } = this.data
    this.setData({ current: current + 1 })
    this.getList(this.data.current, pageSize)
  },

  goPassport(e) {
    wx.navigateTo({
      url: '/visitor_pkg/pages/passport/index?id=' + e.mark.id,
    })
  },

  async getList(current, pageSize) {
    const res = await wx.http({
      url: '/visitor',
      data: { current, pageSize },
    })
    this.setData({
      list: [...this.data.list, ...res.data.rows],
    })
  },

  onLoad() {
    const { current, pageSize } = this.data
    this.getList(current, pageSize)
  },
})
